package cn.iocoder.yudao.module.trade.controller.admin.delivery;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.pickup.DeliveryPickUpStoreCreateReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.delivery.vo.wxexpress.*;
import cn.iocoder.yudao.module.trade.service.delivery.WxExpressService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 微信物流服务")
@RestController
@RequestMapping("/trade/delivery/express-wx")
@Validated
public class WxExpressController {
    @Resource
    private WxExpressService wxExpressService;

    @PostMapping("/add")
    @Operation(summary = "物流助手-生成运单")
    public CommonResult<Boolean> createExpressOrder(@Valid @RequestBody ExpressCreateReqVO reqVO) {
        Boolean result = wxExpressService.createExpressOrder(reqVO);
        return success(result);
    }

    @PostMapping("/channel")
    @Operation(summary = "物流助手-取消运单")
    public CommonResult<Boolean> channelExpressOrder(@Valid @RequestBody ExpressChannelReqVO reqVO) {
        Boolean result = wxExpressService.channelExpressOrder(reqVO);
        return success(result);
    }

    @PostMapping("/get")
    @Operation(summary = "物流助手-获取运单数据")
    public CommonResult<JSONObject> getExpressOrder(@Valid @RequestBody ExpressGetInfoReqVO reqVO) {
        JSONObject obj = wxExpressService.getExpressOrder(reqVO);
        return success(obj);
    }

    /**
     * 该接口用于配置面单打印员，可以设置多个，若需要使用微信打单 PC 软件，才需要调用。
     * 注：面单打印员不需要为小程序项目成员。
     *
     * @param reqVO
     * @return
     */
    @PostMapping("/updatePrinter")
    @Operation(summary = "物流助手-配置面单打印员")
    public CommonResult<Boolean> updateExpressPrinter(@Valid @RequestBody ExpressUpdatePrinter reqVO) {
        Boolean result = wxExpressService.updateExpressPrinter(reqVO);
        return success(result);
    }

    @PostMapping("/getPrinter")
    @Operation(summary = "物流助手-获取面单打印员")
    public CommonResult<JSONObject> getExpressPrinter() {
        JSONObject obj = wxExpressService.getExpressPrinter();
        return success(obj);
    }

    @PostMapping("/getAllDelivery")
    @Operation(summary = "物流助手-获取支持的快递公司列表")
    public CommonResult<JSONObject> getAllDelivery() {
        JSONObject obj = wxExpressService.getAllDelivery();
        return success(obj);
    }
}
